package laogao.bus;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class ThreadTestController {


    private static final Logger log = LoggerFactory.getLogger(ThreadTestController.class);

    @Resource(name = "customExecutor") // 注入你定义的线程池 Bean
    private ThreadPoolTaskExecutor customExecutor;

    @GetMapping("/test/thread-error")
    public String triggerThreadError() {
        customExecutor.execute(() -> {
            try {
                log.info("线程任务开始执行：{}", Thread.currentThread().getName());
                throw new RuntimeException("模拟异常：接口调用中线程出错！");
            } catch (Exception e) {
                log.error("任务中异常：{}", e.getMessage(), e);
            }
        });
        return "任务已提交";
    }

}
